﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CSharp.Libs.Misc;
using CSharp.Libs.ExceptionHandling;


namespace TestingMessageLogging
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MessageLogging ML = new MessageLogging(new ExceptionCollector());

        public MainWindow()
        {
            InitializeComponent();

            ML.AfterAddingMessage += new MessageLogging.AfterAddingMessageEventHandler(ML_AfterAddingMessage);
            ML.AfterDeletingMessage += new MessageLogging.AfterDeletingMessageEventHandler(ML_AfterDeletingMessage);

            ML.MaxBufferSize = 5;

            messageLoggingTextBox1.InitViewModel(ML);
        }



        void ML_AfterAddingMessage(object sender, MessageLoggingEventArgs mlea)
        {
            textBox2.Text = string.Concat(textBox2.Text, mlea.Message.ToString(), Environment.NewLine);
        }

        void ML_AfterDeletingMessage(object sender, MessageLoggingEventArgs mlea)
        {
            string strMessageToDelete = string.Concat(mlea.Message.ToString(), Environment.NewLine);
            textBox2.Text = textBox2.Text.Replace(strMessageToDelete, "");
        }

        
        
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text.Trim() != "")
            {

                MessageItem MI = ML.AddMessage(MessageType.Information, textBox1.Text.Trim());
            }
        }
    }
}
